<!-- 房源回收站 -->
<template>
    <div>
        <div class="search">
            <el-form :inline="true" :model="searchData" size="mini" class="demo-form-inline">
                <el-form-item label="删除日期" prop="start_time">
                    <el-date-picker type="date" placeholder="请选择" v-model="searchData.start_time" value-format="yyyy-MM-dd"></el-date-picker>
                </el-form-item>_
                <el-form-item label="" prop="end_time">
                    <el-date-picker type="date" placeholder="请选择" v-model="searchData.end_time" value-format="yyyy-MM-dd"></el-date-picker>
                </el-form-item>
                <el-form-item label="" prop="keywords">
                    <el-input v-model="searchData.keywords" placeholder="房源编号、栋座、位置、房号、业主姓名" style="width: 250px;"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search" size="mini">查询</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class='content'>
            <div class='list'>
                <el-table :data="list.data" tooltip-effect="dark" style="width: 100%">

                    <el-table-column align="center" prop="property_number" label="房源编号" width="120"></el-table-column>
                    <el-table-column align="center" prop="trading_type" label="交易类型" width="120"></el-table-column>
                    <el-table-column align="center" prop="a_id" label="区县" width="120"></el-table-column>
                    <el-table-column align="center" prop="building_id" label="楼盘字典" width="120"></el-table-column>
                    <el-table-column align="center" prop="few_building" label="栋座" width="120"></el-table-column>
                    <el-table-column align="center" prop="position" label="位置" width="120"></el-table-column>
                    <el-table-column align="center" prop="room_number" label="房号" width="120"></el-table-column>
                    <el-table-column align="center" prop="owner_name" label="业主" width="120"></el-table-column>
                    <el-table-column align="center" prop="r_entrust_at" label="委托时间" width="120"></el-table-column>
                    <el-table-column align="center" prop="u_username" label="房源归属人" width="120"></el-table-column>
                    <el-table-column align="center" prop="deltime" label="删除时间" width="120"></el-table-column>
                    <el-table-column align="center" prop="deldepartment" label="删除人部门" width="120"></el-table-column>
                    <el-table-column align="center" prop="deluser" label="删除人" width="120"></el-table-column>
                    <el-table-column align="center" fixed="right" label="操作" width="160">
                    <template slot-scope="scope">
                        <el-button @click.native.prevent="reduction(scope.row)" type="text" size="small">还原</el-button>
                        <el-button @click.native.prevent="del(scope.row)" type="text" size="small">彻底删除</el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <el-pagination :current-page="current" @current-change="handleCurrentChange" :total="list.total" style="margin-top:30px;"></el-pagination>
            </div>
        </div>
    </div>
</template>
<style>
    .home .view-content{
        width: 87%;
    }
    .el-form-item__label,.el-form-item__content{
        font-size: 12px;
    }
    .el-input{
        padding-right: 5px;
    }
    .el-select-dropdown__item{
        font-size: 12px;
        padding: 0px 10px;
        height: 26px;
        line-height: 26px;
    }
    .el-input,.el-date-editor.el-input{
        width: 145px;
    }
</style>
<script>
    import conf from '../../../config/userconf.js'
    import permconfig from '../../../config/permconfig.js'
    export default {
        data() {
            return {
                list:[],
                searchData: {
                    start_time: '',
                    end_time: '',
                    keywords: '',
                }, 
                current: 1,
                initdate: true,  //默认日期
            }
        },
        methods: {
            /* 列表*/
            getList (data=Object()){
                data.page = this.current;
                conf.reclaim.roomlist(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        // console.log(res);
                        this.list = res.data.data;
                        if(this.initdate){
                            this.searchData.start_time = res.data.start;
                            this.searchData.end_time = res.data.end;
                        }
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else if(res.data.code == -404){
                            this.list = [];
                            if(this.initdate){
                                this.searchData.start_time = res.data.msg.start;
                                this.searchData.end_time = res.data.msg.end;
                            }
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            },
            // 切换页码
            handleCurrentChange(val) {
                this.current = val;
                this.getList();
            },
            /*查询 */
            search () {
                this.initdate = false;
                let data  = this.searchData;
                this.getList(data);
            },
            /*删 */
            del (row,data=Object()) {
                 var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_shanchuhuishouzhanxinxi)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
                this.$confirm('彻底删除房源编号 "'+row.property_number+'" 吗?', '删除房源信息', {  
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    data.id = row.id;
                    conf.reclaim.roomdel(data,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            this.getList();
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }else if(state == 'success'&&res.data.code != 0){
                            if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    })

                }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消删除'
                    });          
                });
            },
            //还原
            reduction(row,data=Object()){
                 var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_huanyuanhuishouzhan)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
                this.$confirm('确认还原房源编号 "'+row.property_number+'" 吗?', '还原房源信息', {  
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    data.id = row.id;
                    conf.room.reclaim(data,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            this.getList();
                            this.$message({
                                type: 'success',
                                message: '还原成功!'
                            });
                        }else if(state == 'success'&&res.data.code != 0){
                            if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    })

                }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消还原'
                    });          
                });
            },
        },
        mounted (){
            this.$nextTick(function(){
                this.getList()
            })
        },
        
    }
</script>